package servlet_pack;

import java.io.IOException;
import java.util.List;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.IUserDao;
import entity.Page;
import entity.Users;
import service.IUserService;
import service.impl.UserServiceImpl;

/**
 * Servlet implementation class QueryByPage
 */
@WebServlet("/QueryByPage")
public class QueryByPage extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public QueryByPage() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String cpage=request.getParameter("pageindex");
		if(cpage==null) {
			cpage="1";
		}
		IUserService iUserService = new UserServiceImpl();
		int count = iUserService.GetAllCount();
		int pageindex=Integer.parseInt(cpage);
		System.out.println(cpage);
		//int pageindex=2;
		Page page = new Page();
		page.setTotalCount(count);//总数据
		page.setCurrentpage(pageindex);//当前页
		int pagesize=5;
		page.setPagesize(pagesize);//页面大小
		List<Users> users=iUserService.querybypage(pageindex, pagesize);
		System.out.println(users);
		System.out.println(count);
		page.setUsers(users);
		request.setAttribute("page", page);
		request.getRequestDispatcher("/User_admin/All_Data.jsp?pageindex=1").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
